using System;
using Spring.Context;
using Spring.Context.Support;
using Spring.Objects.Factory.Config;
using Spring.Objects.Factory.Support;

namespace Jackie.Utility.Spring
{
    public static class SpringExtension
    {
        public static T GetObjectById<T>(this IApplicationContext context, string name) where T : class
        {
            return (context.GetObject(name) as T);
        }

        public static void RegisterObjectDefine(this IApplicationContext context, string name, Type type)
        {
            var xmlContext = context as XmlApplicationContext;
            if (xmlContext == null)
                throw new Exception("");

            xmlContext.RegisterObjectDefinition(name, new RootObjectDefinition(type));
        }
    }
}
